package com.zhong.wechat.handler;

import com.zhong.wechat.enums.WeChatMessageTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class SubscribeMsgHandler implements WeChatMegHandler{
    @Override
    public WeChatMessageTypeEnum getMsgType() {
        return WeChatMessageTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String, String> msgMap) {

        //接收者
        String toUserName = msgMap.get("ToUserName");
        //发送者
        String fromUserName = msgMap.get("FromUserName");
        log.info("用户 {} 关注了公众号",fromUserName);
        return """
                <xml>
                  <ToUserName><![CDATA[${toUser}]]></ToUserName>
                  <FromUserName><![CDATA[${fromUser}]]></FromUserName>
                  <CreateTime>12345678</CreateTime>
                  <MsgType><![CDATA[text]]></MsgType>
                  <Content><![CDATA[感谢您关注jc-club-zhong公众号]]></Content>
                </xml>
                """.replace("${toUser}",fromUserName).replace("${fromUser}",toUserName);
    }
}
